#!/usr/bin/env python
# encoding: utf-8

"""
@version: ??
@author: windblue
@license: Apache Licence 
@contact: q418584383@gmail.com
@site: 
@time: 2017/11/11 21:14
"""
from urllib import request
import http.cookiejar
url = 'http://www.baidu.com'

response1 = request.urlopen(url)
print(len(response1.read()))
print(response1.getcode())


req = request.Request(url)
req.add_header("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36")
req.add_header("Origin","http://www.thsrc.com.tw")

response2=request.urlopen(req)
print(response2.read())
print(response2.getcode())

print('新方法')
cj= http.cookiejar.CookieJar()
handler = request.HTTPCookieProcessor(cookiejar = cj)
opener = request.build_opener(handler,request.HTTPHandler(debuglevel = 1))
s = opener.open('http://www.baidu.com')
print(s.read())
print(response2.getcode())
s.close






